package com.example.database.service.impl;

import com.example.database.dao.DeptInstructorDao;
import com.example.database.dao.StudentDao;
import com.example.database.entity.AdmissionForm;
import com.example.database.entity.DeptInstructor;
import com.example.database.entity.LeavingForm;
import com.example.database.service.DeptInstructorService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;

@Service
public class DeptInstructorServiceImpl implements DeptInstructorService
{
    @Resource
    private DeptInstructorDao deptInstructorDao;

    @Resource
    private StudentDao studentDao;

    @Override
    public boolean login(Integer teacherId, String password, HttpSession session)
    {
        DeptInstructor deptInstructor = deptInstructorDao.findDeptInstructorById(teacherId);
        if (deptInstructor != null && password.equals(deptInstructor.getPassword()))
        {
            session.setAttribute("deptInstructor", deptInstructor);
            return true;
        }
        return false;
    }

    @Override
    public List<AdmissionForm> findAdmissionFormByDepartment(Integer departmentId)
    {
        return studentDao.findAdmissionFormByDepartment(departmentId);
    }

    @Override
    public List<LeavingForm> findLeavingFormByDepartment(Integer departmentId)
    {
        return studentDao.findLeavingFormByDepartment(departmentId);
    }

    @Override
    public Boolean processAdmissionFormByDeptInstructor(Integer formId, boolean operation, String reason)
    {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return studentDao.processAdmissionFormByDeptInstructor(formId, operation, df.format(System.currentTimeMillis()), reason);
    }

    @Override
    public Boolean processLeavingFormByDeptInstructor(Integer formId, boolean operation, String reason)
    {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return studentDao.processLeavingFormByDeptInstructor(formId, operation, df.format(System.currentTimeMillis()),reason);
    }
}
